//
//  VistorViewController.swift
//  Swiftsweibo
//
//  Created by 张鹏飞 on 16/1/1.
//  Copyright © 2016年 张鹏飞. All rights reserved.
//

import UIKit

class VistorViewController: UITableViewController {

    private var userLogon = UserAccountViewModel.sharedUserAccount.userLogon
    
/// 访客视图
//    var vistorView: VistorView()?
    var visitorView: VistorView?
    
    
    override func loadView() {
        
        userLogon ? super.loadView() : setUpVistorView()
    }
    
    private func setUpVistorView(){
        
        visitorView = VistorView()
//     visitorView?.delegate = self
        
        visitorView?.registerButton.addTarget(self, action: "vistorViewDidRegister", forControlEvents: UIControlEvents.TouchUpInside)
        visitorView?.loginButton.addTarget(self, action: "vistorViewDidLogin", forControlEvents: UIControlEvents.TouchUpInside)
        view = visitorView
//        view.backgroundColor = UIColor.orangeColor()
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "vistorViewDidRegister")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "vistorViewDidLogin")
    }
}

///MARK: - 访客视图监听方法
extension VistorViewController {

    func vistorViewDidRegister() {
        print("注册")
    }
    func vistorViewDidLogin() {
        let vc = OAuthViewController()
        let nav = UINavigationController(rootViewController: vc)
        presentViewController(nav, animated: true, completion: nil)
    }
}